package com.learn.jms.test;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * 《Spring源码深度解析》第13章 Spring消息
 * 发送端实现
 * ActiveMQ下载：http://activemq.apache.org/activemq-5015009-release
 * Windows系统下双击 /bin/win64/activemq.bat 启动消息服务器
 */
public class Sender {
    public static void main(String[] args) throws Exception {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        Connection connection = connectionFactory.createConnection();
        //connection.start();

        Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createQueue("my-queue");
        MessageProducer producer = session.createProducer(destination);
        for (int i = 0; i < 3; i++) {
            TextMessage message = session.createTextMessage("大家好这是个测试");
            Thread.sleep(1000);
            // 通过消息生产者发出消息
            producer.send(message);
        }
        session.commit();
        session.close();
        connection.close();
    }
	//  INFO | Successfully connected to tcp://localhost:61616
}
